package com.group.activity.controller;

import com.group.activity.entity.SecondKillConfigurationEntity;
import com.group.activity.service.SecondKillConfigurationService;
import com.group.common.utils.PageUtils;
import com.group.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 秒杀配置表
 *
 * @author lins
 * @email 695565697@qq.com
 * @date 2021-11-15 09:02:32
 */
@RestController
@RequestMapping("activity/secondkillconfiguration")
public class SecondKillConfigurationController {
    @Autowired
    private SecondKillConfigurationService secondKillConfigurationService;
    /*
    * 查询最近三天秒杀场次和商品信息
    * */
    @RequestMapping("/getSeckillLasted3DaysInfo")
    public R getSeckillLasted3DaysInfo(){
        List<SecondKillConfigurationEntity> entities = secondKillConfigurationService.getSeckillLasted3DaysInfo();
        return R.ok().setData(entities);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = secondKillConfigurationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		SecondKillConfigurationEntity secondKillConfiguration = secondKillConfigurationService.getById(id);

        return R.ok().put("secondKillConfiguration", secondKillConfiguration);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SecondKillConfigurationEntity secondKillConfiguration){
		secondKillConfigurationService.save(secondKillConfiguration);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SecondKillConfigurationEntity secondKillConfiguration){
		secondKillConfigurationService.updateById(secondKillConfiguration);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		secondKillConfigurationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
